
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>跨域问题 - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>跨域问题 - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">在 SpringBoot 中，如何通过实现 `WebMvcConfigurer` 接口来配置全局跨域（CORS）规则？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">通过重写 `addCorsMappings` 方法，使用 `CorsRegistry` 对象来添加映射。例如，`registry.addMapping("/**")` 对所有路径生效，然后可以链式调用 `.allowedOrigins("*")`, `.allowCredentials(true)`, `.allowedMethods(...)` 和 `.maxAge(...)` 等方法来定义具体的跨域策略。</div>
          </div>
          <div class="card-source">来源: SpringBoot解决</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">在 SpringBoot 中，除了全局配置外，如何仅为一个特定的 Controller 类启用跨域支持？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">可以直接在 Controller 类或方法上使用 `@CrossOrigin` 注解。例如，`@CrossOrigin(origins = "http://192.168.1.10:8080", maxAge = 3600)` 可以为该 Controller 指定允许的来源域和预检请求的缓存时间。</div>
          </div>
          <div class="card-source">来源: SpringBoot解决</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">配置</div>
          <div class="card-question">在文档提供的 Spring Cloud Gateway YAML 配置中，是如何配置全局跨域的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">配置</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">通过在 `spring.cloud.gateway.globalcors.cors-configurations` 路径下，为所有路径 `[/**]` 定义跨域规则，具体包括设置 `allowedOrigins`、`allowedMethods`、`allowedHeaders`、`allowCredentials` 和 `maxAge` 等属性。</div>
          </div>
          <div class="card-source">来源: gateway网关中解决跨域问题</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">使用原生 `Filter` 解决跨域问题的基本原理是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">基本原理是在 `doFilter` 方法中，将 `ServletResponse` 强制转换为 `HttpServletResponse`，然后通过调用 `response.setHeader()` 方法，手动为响应添加 CORS 相关的 HTTP 头部信息，例如 `Access-Control-Allow-Origin` 和 `Access-Control-Allow-Methods`。</div>
          </div>
          <div class="card-source">来源: 原生Filter解决</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">配置</div>
          <div class="card-question">在文档提供的 `CorsFilter` 示例中，通过 `CorsConfiguration` 对象配置了哪些主要的跨域参数？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">配置</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">配置了四个主要参数：1. `addAllowedOrigin("*")`：允许所有域访问。2. `addAllowedHeader("*")`：允许请求头中携带任何参数。3. `addAllowedMethod("*")`：允许所有请求方法访问。4. `setAllowCredentials(true)`：允许浏览器读取 response 的内容。</div>
          </div>
          <div class="card-source">来源: SpringBoot解决</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">在跨域配置中，设置 `maxAge`（例如 `maxAge(3600)`）的作用是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`maxAge` 用于设置预检请求（pre-flight request）的缓存时间，单位为秒。文档中的 `maxAge(3600)` 表示浏览器可以在 3600 秒（即1小时）内缓存该预检请求的结果，在此期间对同一 URL 的请求无需再次发送预检请求。</div>
          </div>
          <div class="card-source">来源: SpringBoot解决</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
